<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Google Agenda's</title>
<link href="opmaak.css" rel="stylesheet" type="text/css" media="screen" />
</head>
  <script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript">
	$(document).ready(function(){
	
	function myfunction () 
		{
			var ind = document.getElementById('select').selectedIndex;
			if (ind>0) 
			{ 
				$('#cal').remove();
				$('#br').remove();
				$('form').after('<br id="br" /><iframe id="cal" src="http://www.google.com/calendar/embed?src='+document.getElementById('select').options[ind].value+'&ctz=Europe/Amsterdam" width="400" height="300" frameborder="0" scrolling="no"></iframe><br id="br" />');
				$('#content').css({ "width" : "410px" })
			}
		}
	window.onload=function () 
		{
			if (document.getElementById('select')) 
			{
				document.getElementById('select').onchange=function() { myfunction(); }
		}
		};
	
	});
	function laadscherm()
	{
 		$('body').empty();
		$('body').append('<img src="http://www.club-connect.nl/hyvessync/images/loading.gif" title="loading" alt="loading" />')
	}
</script>

<body>

<?php

require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata');
Zend_Loader::loadClass('Zend_Gdata_AuthSub');
Zend_Loader::loadClass('Zend_Gdata_Calendar');

if(isset($_SESSION['hyvesid']))
{
	// Connection DB
	include('database_inc.php');
	$db = mysql_connect($server,$gebruikersnaam, $password);
	mysql_select_db($database, $db);
	
	// Execute Query
	$sql = "SELECT * FROM users WHERE hyvesID = '".$_SESSION['hyvesid']."'";
	$result = mysql_query($sql, $db);
	$regel = mysql_fetch_assoc($result);
		
			 // Create a valid header containing AuthSubtoken
			 $client = Zend_Gdata_AuthSub::getHttpClient($regel['googleAuthSubToken']);
			 
			  // Get all calendars of user
			  $gdataCal = new Zend_Gdata_Calendar($client);
			  $calFeed = $gdataCal->getCalendarListFeed() 
			  ?>
              <div id="content">
              <div id="headert"><table><tr><td><img src="images/hyvessynclogo.png" title="HyvesSync" alt="HyvesSync" /></td><td><label class="title">HyvesSync</label></td></tr></table></div>

			  <p>Maak een keuze uit het drop-down menu om een van jouw agenda's te bekijken.</p>
              <form>
              <select id="select">
              <option value=""></option>
              <?php
			  	foreach ($calFeed as $calendar) 
				{
					if($calendar->accessLevel == 'owner' || $calendar->accessLevel == 'editor')
					{
						$urlparts = explode('/',$calendar->getAlternateLink()->href);
						$calendarid = $urlparts[5];
						?>
                        <option value="<?php echo $calendarid; ?>">
						<?php echo $calendar->title->text; ?>
                        </option>                                     
						<?php 
					} 
				}
				?>
                </select>
               </form>
               <br />
              <a href="index1.php" onclick="laadscherm()">Ga terug</a>
              </div>
              <?php
}
else
{
?>
<p>U heeft geen toegang tot deze pagina.</p>
<?php
}
	 
?>

</body>
</html>
